package com.ruoyi.hd.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hd.domain.HdProduct;
import com.ruoyi.hd.service.IHdProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品管理Controller
 * 
 * @author ruoyi
 * @date 2022-05-29
 */
@RestController
@RequestMapping("/hd/product")
public class HdProductController extends BaseController
{
    @Autowired
    private IHdProductService hdProductService;

    /**
     * 查询产品管理列表
     */
    @PreAuthorize("@ss.hasPermi('hd:product:list')")
    @GetMapping("/list")
    public AjaxResult list(HdProduct hdProduct)
    {
        List<HdProduct> list = hdProductService.selectHdProductList(hdProduct);
        return AjaxResult.success(list);
    }

    /**
     * 导出产品管理列表
     */
    @PreAuthorize("@ss.hasPermi('hd:product:export')")
    @Log(title = "产品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HdProduct hdProduct)
    {
        List<HdProduct> list = hdProductService.selectHdProductList(hdProduct);
        ExcelUtil<HdProduct> util = new ExcelUtil<HdProduct>(HdProduct.class);
        util.exportExcel(response, list, "产品管理数据");
    }

    /**
     * 获取产品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('hd:product:query')")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return AjaxResult.success(hdProductService.selectHdProductByProductId(productId));
    }

    /**
     * 新增产品管理
     */
    @PreAuthorize("@ss.hasPermi('hd:product:add')")
    @Log(title = "产品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HdProduct hdProduct)
    {
        return toAjax(hdProductService.insertHdProduct(hdProduct));
    }

    /**
     * 修改产品管理
     */
    @PreAuthorize("@ss.hasPermi('hd:product:edit')")
    @Log(title = "产品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HdProduct hdProduct)
    {
        return toAjax(hdProductService.updateHdProduct(hdProduct));
    }

    /**
     * 删除产品管理
     */
    @PreAuthorize("@ss.hasPermi('hd:product:remove')")
    @Log(title = "产品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(hdProductService.deleteHdProductByProductIds(productIds));
    }
}
